package com.lwm.controller;

import com.lwm.domain.ResponseResult;
import com.lwm.domain.SalesOrder;
import com.lwm.dto.PageParams;
import com.lwm.dto.SalesOrderDto;
import com.lwm.service.SalesOrderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/salesOrder")
public class SalesOrderController {
    @Resource
    private SalesOrderService salesOrderService;

    /**
     * 获取全部
     *
     * @return {@link ResponseResult}<{@link Object}>
     */
    @GetMapping
    private ResponseResult<Object> getAll() {
        return salesOrderService.getAll();
    }


    /**
     * 收到分页
     *
     * @param salesOrderDto 销售订单dto
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PostMapping("/page")
    public ResponseResult<Object> getPage(@RequestBody SalesOrderDto salesOrderDto) {
        return salesOrderService.getPage(salesOrderDto);
    }

    /**
     * 添加
     *
     * @param salesOrder 销售订单
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PostMapping
    public ResponseResult<Object> save(@RequestBody SalesOrder salesOrder) {
        return salesOrderService.insert(salesOrder);
    }

    /**
     * 更新
     *
     * @param salesOrder 销售订单
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PutMapping
    public ResponseResult<Object> update(@RequestBody SalesOrder salesOrder) {
        return salesOrderService.updateById(salesOrder);
    }

    /**
     * 删除
     *
     * @param ids 编码
     * @return {@link ResponseResult}<{@link Object}>
     */
    @DeleteMapping("/{ids}")
    public ResponseResult<Object> remove(@PathVariable("ids") List<Long> ids) {
        System.out.println(ids);
        return salesOrderService.removeBatch(ids);
    }
}
